package com.hy.logtrace.domain.resp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 默认的返回对象
 * @param <T>
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private final static String SUCCESS_CODE = "200";
    private final static String FAIL_CODE = "500";

    private final static String SUCCESS_MSG = "success";
    private final static String FAIL_MSG = "fail";

    private T data;
    private String code;
    private String msg;

    public static <T> Result<T> success(T data) {
        return new Result<T>(data, SUCCESS_CODE, SUCCESS_MSG);
    }

    public static <T> Result<T> success(String msg) {
        return new Result<T>(null, SUCCESS_CODE, msg);
    }

    public static <T> Result<T> success() {
        return new Result<T>(null, SUCCESS_CODE, SUCCESS_MSG);
    }

    public static <T> Result<T> fail(String msg) {
        return new Result<T>(null, FAIL_CODE, msg);
    }

    public static <T> Result<T> fail() {
        return new Result<T>(null, FAIL_CODE, FAIL_MSG);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<T>(data, FAIL_CODE, FAIL_MSG);
    }
}
